#include "device_manage/device_manage.h"

/**************************************************************************gpio device***************************************************** */
static device_t gpio_device[] = {
    {
        .name = "gpio0",
        .type = DEVICE_TYPE_GPIO,
        .compat = "generic,gpio",
        .user_data = (void *)(uintptr_t)GPIO_DEVICE_NUM_0,
    },
    {
        .name = "gpio1",
        .type = DEVICE_TYPE_GPIO,
        .compat = "generic,gpio",
        .user_data = (void *)(uintptr_t)GPIO_DEVICE_NUM_1,
    },
    {
        .name = "gpio2",
        .type = DEVICE_TYPE_GPIO,
        .compat = "generic,gpio",
        .user_data = (void *)(uintptr_t)GPIO_DEVICE_NUM_2,
    },
    {
        .name = "gpio3",
        .type = DEVICE_TYPE_GPIO,
        .compat = "generic,gpio",
        .user_data = (void *)(uintptr_t)GPIO_DEVICE_NUM_3,
    },
    {
        .name = "gpio4",
        .type = DEVICE_TYPE_GPIO,
        .compat = "generic,gpio",
        .user_data = (void *)(uintptr_t)GPIO_DEVICE_NUM_4,
    },
};
static driver_t *gpio_driver[] = {
    &gpio_device_driver,
};

static int gpio_driver_device_match(void *dev, void *drv){
    return 0;
}

static bus_t gpio_bus = {
    .name = "gpio_bus",
    .match = gpio_driver_device_match,
};

/**************************************************************************uart device***************************************************** */
static device_t uart_device[] = {
    {
        .name = "uart0",
        .type = DEVICE_TYPE_UART,
        .compat = "generic,uart",
        .user_data = (void *)(uintptr_t)UART_PORT_0,
    },
};
static driver_t *uart_driver[] = {
    &uart_device_driver,
};

static int uart_driver_device_match(void *dev, void *drv){
    return 0;
}

static bus_t uart_bus = {
    .name = "uart_bus",
    .match = uart_driver_device_match,
};

void device_driver_init(void) {
    for (int i = 0; i< DEVICE_ARRAY_SIZE(gpio_driver); i++) {
        driver_register(gpio_driver[i], &gpio_bus);
    }
    for (int i = 0; i < DEVICE_ARRAY_SIZE(gpio_device); i++) {
        device_register(&gpio_device[i], &gpio_bus);
    }

    for (int i = 0; i< DEVICE_ARRAY_SIZE(uart_driver); i++) {
        driver_register(uart_driver[i], &uart_bus);
    }
    for (int i = 0; i < DEVICE_ARRAY_SIZE(uart_device); i++) {
        device_register(&uart_device[i], &uart_bus);
    }
}
